package com.design.single;

import java.util.HashMap;
import java.util.Map;

public class SingleRegistry {
	private static Map<String,Object> registryMap = new HashMap<String,Object>();
	
	static{
		SingleRegistry signRegi = new SingleRegistry();
		registryMap.put(signRegi.getClass().getName(), signRegi);
	}
	
	public static SingleRegistry getSingle(String name){
		if(name==null){
			name = SingleRegistry.class.getName();
		}
		
		//System.out.println(registryMap.get(name) + "   ......");
		
		((SingleRegistry)registryMap.get(SingleRegistry.class.getName())).about();
		
		
		if(registryMap.get(name)==null){
			try {
				registryMap.put(name, Class.forName(name).newInstance());
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return (SingleRegistry)registryMap.get(name);
	}
	
	public void about(){
		System.out.println("i am parent");
	}
	
}
